package com.basker.pisces.concurrent.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import com.basker.pisces.concurrent.collection.IConcurrentCollectionManager;
import com.basker.pisces.concurrent.collection.LocalCollectionManager;
import com.basker.pisces.config.Constants;

@Configuration
public class LocalConcurrentCollectionManagerConfiguration {
    public static final String DEFAULT_CONCURRENT_COLLECTION_MANAGER = Constants.DEFAULT_CONCURRENT_COLLECTION_MANAGER;

    /**
     * 如果不存在其他{@value #DEFAULT_COLLECTION_MANAGER}的IConcurrentCollectionManager,则默认缓存管理器为{@link LocalCollectionManager}
     *
     * @return
     */
    @Bean(name = DEFAULT_CONCURRENT_COLLECTION_MANAGER)
    @Primary
    @ConditionalOnMissingBean(name = DEFAULT_CONCURRENT_COLLECTION_MANAGER)
    public IConcurrentCollectionManager localCollectionManager() {
        return new LocalCollectionManager(DEFAULT_CONCURRENT_COLLECTION_MANAGER);
    }
}
